package net.godbirds.api.business;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import net.godbirds.Constant;
import net.godbirds.domain.mapper.TDefAppealMapper;
import net.godbirds.domain.model.TDefAppeal;
import net.godbirds.domain.model.TDefUser;

/**
 * 申诉控制器
 * @author godbi
 *
 */
@RestController
@RequestMapping("/appeal")
public class AppealController {

	@Autowired
	TDefAppealMapper tDefAppealMapper;
	
	/**
	 * 申诉提交
	 * @param request
	 * @param tAppeal
	 * @return
	 */
	@RequestMapping(value="/application",method=RequestMethod.POST,produces="application/json;charset=utf-8")
	public Map<String,Object> appUrl(HttpServletRequest request,@RequestBody TDefAppeal tAppeal) {
		Map<String,Object> rtvMap = new HashMap<String,Object>();
		if(tAppeal == null) {
			rtvMap.put("msg", "无对应申诉信息");
			return rtvMap;
		}
		if(tAppeal.getName() == null) {
			rtvMap.put("msg", "无对应申诉人信息");
			return rtvMap;
		}
		TDefUser tUser = (TDefUser)request.getSession().getAttribute(Constant.SESSION_USER_KEY);
		if(tUser == null) {
			rtvMap.put("msg", "长时间为操作，SESSION过期，请重新登录使用！");
			return rtvMap;
		}
		tAppeal.setStatus("-1");//申请成功，系统处理中
		tAppeal.setInsertTime(new Date());
		tAppeal.setLastModifyTime(new Date());
		tAppeal.setOperator(tUser.getUserCode());
		tAppeal.setLastModifyer(tUser.getUserCode());
		tDefAppealMapper.insert(tAppeal);
		rtvMap.put("msg", "√ 申诉成功，请等待系统处理，您可至【案件追踪】查询和追踪。");
		return rtvMap;
	}
}
